﻿/*
 * ©2009-2010 XELF
 * http://xelf.info
 */

using System;

#if XNA || WINDOWS_PHONE
using Microsoft.Xna.Framework;
#endif

namespace XELF.Framework {
#if XNA || WINDOWS_PHONE
	public static partial class MatrixHelper {
#else
	public partial struct Matrix {
#endif
		/// <summary>
		/// 方向ベクトルから回転行列を作る。方向以外の軸は特にこだわらない。
		/// </summary>
		/// <param name="direction"></param>
		/// <returns></returns>
		public static Matrix CreateFromDirection(Vector3 direction) {
			direction.Normalize();
			var x = new Vector3(direction.Z, -direction.X, direction.Y);
			Vector3 y;
			Vector3.Cross(ref x, ref direction, out y);
			y.Normalize();
			Vector3.Cross(ref y, ref direction, out x);
			return new Matrix(
				x.X, y.X, direction.X, 0,
				x.Y, y.Y, direction.Y, 0,
				x.Z, y.Z, direction.Z, 0,
				0, 0, 0, 1);
		}

	}

}
